from aiogram_dialog import DialogManager

from src.core.models.enums import CurrencySymbol, LangCode
from src.database.services import BotSettingsService, SubscriptionService, UserService


async def subscriptions_prices_getter(
    dialog_manager: DialogManager,
    bot_settings_service: BotSettingsService,
    user_service: UserService,
    **kwargs
):
    user = await user_service.get_user_by_telegram_id(dialog_manager.event.from_user.id)
    bot_settings = await bot_settings_service.get_bot_settings()

    currency_symbol = CurrencySymbol.ru
    price_one_calendar = bot_settings.price_one_calendar_ru
    price_seven_calendars = bot_settings.price_seven_calendars_ru
    price_unlimited = bot_settings.price_unlimited_ru

    if user.lang_code == LangCode.en:
        currency_symbol = CurrencySymbol.en
        price_one_calendar = bot_settings.price_one_calendar_en
        price_seven_calendars = bot_settings.price_seven_calendars_en
        price_unlimited = bot_settings.price_unlimited_en
    elif user.lang_code == LangCode.uk:
        currency_symbol = CurrencySymbol.uk
        price_one_calendar = bot_settings.price_one_calendar_uk
        price_seven_calendars = bot_settings.price_seven_calendars_uk
        price_unlimited = bot_settings.price_unlimited_uk

    return {
        "price_one_calendar": price_one_calendar,
        "price_seven_calendars": price_seven_calendars,
        "price_unlimited": price_unlimited,
        "currency_symbol": currency_symbol.value,
    }


async def user_subscription_getter(
    dialog_manager: DialogManager, subscription_service: SubscriptionService, **kwargs
):
    user_subscription = await subscription_service.get_active_user_subscription(
        dialog_manager.event.from_user.id
    )

    return {
        "start_date": user_subscription.start_date,
        "end_date": user_subscription.end_date,
    }
